import request from '@/utils/request'
import store from '@/store/index'
import { getToken } from '@/utils/auth'

export function addCampus(campus) {
  return request({
    url: '/campus/add',
    method: 'post',
    data: {
      'campusName': campus.campusName,
      'campusImg': campus.campusImg,
      'campusInfo': campus.campusInfo,
      'campusState': 0,
      'campusHours': campus.campusHours,
      'area': campus.area,
      'provice': campus.provice,
      'city': campus.city,
      'district': campus.district,
      'conntact': campus.conntact,
      'contactNumber': campus.contactNumber,
      'orgId': campus.orgId,
      'head': campus.head,
      'account': campus.account,
      'bank': campus.bank,
      'campusEmail': campus.campusEmail,
      'contactTel': campus.contactTel,
      'orgType': campus.orgType,
      'campusMid': campus.campusMid
    }
  })
}

export function updateCampus(id, campus) {
  return request({
    url: '/campus/update',
    method: 'post',
    data: {
      'id': id,
      'campusId': campus.campusId,
      'campusName': campus.campusName,
      'campusImg': campus.campusImg,
      'campusInfo': campus.campusInfo,
      'campusState': campus.campusState,
      'campusHours': campus.campusHours,
      'area': campus.area,
      'provice': campus.provice,
      'city': campus.city,
      'district': campus.district,
      'conntact': campus.conntact,
      'contactNumber': campus.contactNumber,
      'orgId': campus.orgId,
      'head': campus.head,
      'account': campus.account,
      'bank': campus.bank,
      'campusEmail': campus.campusEmail,
      'contactTel': campus.contactTel,
      'orgType': campus.orgType,
      'campusMid': campus.campusMid
    }
  })
}

export function getAllCampus() {
  return request({
    url: '/campus/all',
    method: 'get'
  })
}

export function getCampusByRe() {
  return request({
    url: '/campus/referenceId/Allcampus',
    method: 'get',
    params: {
      referenceId: getToken()
    }
  })
}

export function getCampusById(id) {
  return request({
    url: '/campus/id',
    method: 'get',
    params: {
      id: id
    }
  })
}

export function updateStatusById(id, state) {
  return request({
    url: '/campus/updateState',
    method: 'post',
    params: {
      id: id,
      state: state
    }
  })
}

export function deleteById(id) {
  return request({
    url: '/campus/delete',
    method: 'post',
    params: {
      id: id
    }
  })
}

export function getCampusByHead() {
  return request({
    url: '/campus/head',
    method: 'get',
    params: {
      head: store.getters.token
    }
  })
}

export function getCampusByOrg(orgId) {
  return request({
    url: '/campus/orgId',
    method: 'get',
    params: {
      orgId: orgId
    }
  })
}

export function conditionSearch(search) {
  return request({
    url: '/campus/mohu/condition/search',
    method: 'post',
    data: {
      campusName: search.campusName,
      provice: search.provice,
      conntact: search.conntact,
      headName: search.head,
      orgName: search.org
      // userid: getToken()
    }
  })
}

export function conditionSearch2(search) {
  return request({
    url: '/campus/mohu/condition/search',
    method: 'post',
    data: {
      campusName: search.campusName,
      provice: search.provice,
      conntact: search.conntact,
      headName: search.head,
      orgName: search.org,
      orgHead: getToken()
    }
  })
}

export function mohuSearch(str) {
  return request({
    url: '/campus/search2',
    method: 'get',
    params: {
      str: str,
      userid: getToken()
    }
  })
}
